package com.lulu.landslidedemo04;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.TextView;
import android.widget.Toast;
import com.lulu.landslidedemo04.model.TestModel;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements LandSlideView.OnLandViewPageChangeListener<TestModel>, LandSlideView.OnItemClickListener, LandSlideView.OnItemLongClickListener {

    private static final String TAG = "lulu";
    private LandSlideView<TestModel> mLandSlideView;
    private LandSlideAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final List<TestModel> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            list.add(new TestModel("测试题目：" + i));
        }
        mLandSlideView = (LandSlideView) findViewById(R.id.land_slide_view);

        mAdapter = new LandSlideAdapter(this);
        mLandSlideView.setAdapter(mAdapter);
        mAdapter.setData(list);

        TextView view = new TextView(this);
        view.setText("这是一个测试的TextView");
        mLandSlideView.addFooterView(view);

        mLandSlideView.setPageChangeListener(this);
        mLandSlideView.setOnItemClickListener(this);
        mLandSlideView.setOnItemLongClickListener(this);


    }

    @Override
    protected void onResume() {
        super.onResume();
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onChangePage(int currentPagerIndex, int pageCount, int changeMode, List<TestModel> currentPagerList) {
        //Log.d(TAG, "onChangePage() called with: currentPagerIndex = [" + currentPagerIndex + "], pagerCount = [" + pagerCount + "], changeMode = [" + changeMode + "], currentPagerCards = [" + currentPagerList + "]");
        switch (changeMode) {
            case PAGER_CHANGE_MODE_NEXT_END:
                Toast.makeText(this, "到达尾部", Toast.LENGTH_SHORT).show();
                break;
            case PAGER_CHANGE_MODE_PRE_END:
                Toast.makeText(this, "到达顶部", Toast.LENGTH_SHORT).show();
                break;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(this, "当前位置：" + position, Toast.LENGTH_SHORT).show();
        mLandSlideView.removeFooterView();
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
        Toast.makeText(this, "长按事件：" + position, Toast.LENGTH_SHORT).show();
        TextView view1 = new TextView(this);
        view1.setText("新添加的！！！");
        mLandSlideView.addFooterView(view1);
        mAdapter.notifyDataSetChanged();
        return true;
    }


}
